<template>
  <el-select v-model="agentList"
             multiple
             filterable
             clearable size="small"
             default-first-option
             @change="handleOptionClick"
             placeholder="--区域--">
    <el-option
      v-for="items in restaurants"
      :key="items.id" :label="items.name" :value="items.id">
    </el-option>
  </el-select>


</template>
<script>
  export default {
    props: {
      // 接收一个由父级组件传递过来的值
      agentids: Array,
    },
    data() {
      return {
        restaurants: []
      }
    },
    computed: {
      restaurants() { // 区域数据
        return this.$store.state.agentList
      }
    },
    methods: {
      handleOptionClick(val) {
        this.$emit('listenToChildEvent', val)
      },
      loadAll() {
        this.$http.get('/server/agent/citySelect').then((res) => {
          if (res.data.success) {
            this.restaurants = res.data.data
            if (this.restaurants.length == 1) {
              this.agentList.push(this.restaurants[0].id)
              this.handleOptionClick(this.agentList)
            }
          }
        })
      }
    },
    mounted() {
      this.loadAll()
    }
  }
</script>
